Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

module.exports   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 9.4285
1
module.exports = function(GedcomX){
2
  
3
  var utils = require('../utils'),
4
      Base = require('../Base');
5
  
6
  /**
7
   * A view of a family that consists of up to two parents and a list of children
8
   * who have that set of parents in common. While the Relationship data type 
9
   * carries the canonical information about the nature of the relationship
10
   * between the each pair of persons, the FamilyView is designed as a convenience
11
   * for display purposes.
12
   * 
13
   * @constructor
14
   * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
15
   */
16
  var FamilyView = function(json){
17
    
18
    // Protect against forgetting the new keyword when calling the constructor
19
    if(!(this instanceof FamilyView)){
20
      return new FamilyView(json);
21
    }
22
    
23
    // If the given object is already an instance then just return it. DON'T copy it.
24
    if(FamilyView.isInstance(json)){
25
      return json;
26
    }
27
    
28
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  };
30
  
31
  FamilyView.prototype = Object.create(Base.prototype);
32
  
33
  FamilyView._gedxClass = FamilyView.prototype._gedxClass = 'GedcomX.FamilyView';
34
  
35
  FamilyView.jsonProps = [
36
    'parent1',
37
    'parent2',
38
    'children'
39
  ];
40
  
41
  /**
42
   * Check whether the given object is an instance of this class.
43
   * 
44
   * @param {Object} obj
45
   * @returns {Boolean}
46
   */
47
  FamilyView.isInstance = function(obj){
48
    return utils.isInstance(obj, this._gedxClass);
49
  };
50
51
  /**
52
   * Initialize from JSON
53
   * 
54
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
55
   * @return {FamilyView} this
56
   */
57
  FamilyView.prototype.init = function(json){
58
    
59
    Base.prototype.init.call(this, json);
60
    
61
    if(json){
62
      this.setParent1(json.parent1);
63
      this.setParent2(json.parent2);
64
      this.setChildren(json.children);
65
    }
66
    return this;
67
  };
68
  
69
  /**
70
   * Set parent1
71
   * 
72
   * @param {ResourceReference} parent1
73
   * @return {FamilyView} this
74
   */
75
  FamilyView.prototype.setParent1 = function(parent1){
76
    if(parent1){
77
      this.parent1 = GedcomX.ResourceReference(parent1);
78
    }
79
    return this;
80
  };
81
  
82
  /**
83
   * Get parent1
84
   * 
85
   * @return {ResourceReference}
86
   */
87
  FamilyView.prototype.getParent1 = function(){
88
    return this.parent1;
89
  };
90
  
91
  /**
92
   * Set parent2
93
   * 
94
   * @param {ResourceReference} parent2
95
   * @return {FamilyView} this
96
   */
97
  FamilyView.prototype.setParent2 = function(parent2){
98
    if(parent2){
99
      this.parent2 = GedcomX.ResourceReference(parent2);
100
    }
101
    return this;
102
  };
103
  
104
  /**
105
   * Get parent2
106
   * 
107
   * @return {ResourceReference}
108
   */
109
  FamilyView.prototype.getParent2 = function(){
110
    return this.parent2;
111
  };
112
  
113
  /**
114
   * Get children
115
   * 
116
   * @return {ResourceReference[]} children
117
   */
118
  FamilyView.prototype.getChildren = function(){
119
    return this.children || [];
120
  };
121
  
122
  /**
123
   * Set children
124
   * 
125
   * @param {ResourceReference[]} children
126
   * @return {FamilyView} this
127
   */
128
  FamilyView.prototype.setChildren = function(children){
129
    return this._setArray(children, 'children', 'addChild');
130
  };
131
  
132
  /**
133
   * Add a child
134
   * 
135
   * @param {ResourceReference} child
136
   * @return {FamilyView} this
137
   */
138
  FamilyView.prototype.addChild = function(child){
139
    return this._arrayPush(child, 'children', GedcomX.ResourceReference);
140
  };
141
  
142
  /**
143
   * Export the object as JSON
144
   * 
145
   * @return {Object} JSON object
146
   */
147
  FamilyView.prototype.toJSON = function(){
148
    return this._toJSON(Base, FamilyView.jsonProps);
149
  };
150
  
151
  GedcomX.FamilyView = FamilyView;
152
  
153
};